/*
 * MainFrame.java
 *
 * Created on 24 Feb, 2010;
 */

package com.ahmad.fvautoclicker.v2;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * 
 * @author Ahmad Nadeem<br>
 *         <a mailto:"ahmad.nk@gmail.com">
 */
public class MainFrame extends javax.swing.JFrame implements
		WindowFocusListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** Creates new form mainFrame */
	public MainFrame() {
		initComponents();
		setAlwaysOnTop(true);

//		// Get the native look and feel class name
//		String nativeLF = UIManager.getSystemLookAndFeelClassName();
//		// Install the look and feel
//		try {
//		    UIManager.setLookAndFeel(nativeLF);
//		} catch (InstantiationException e) {
//		} catch (ClassNotFoundException e) {
//		} catch (UnsupportedLookAndFeelException e) {
//		} catch (IllegalAccessException e) {
//		}

	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		bg = new TransparentScreen(this);

		setDefaultCloseOperation(EXIT_ON_CLOSE);

		getContentPane().setLayout(null);

		setTitle("FV Auto Clicker v 0.2 :: powered by Ahmad Nadeem");
		setName("mainFrame");

		getContentPane().add(bg);
		bg.setBounds(0, 0, 880, 510);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		bg.setSize(d);
		bg.refresh();

		pack();
	}// </editor-fold>

	// GEN-END:initComponents

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				MainFrame application = new MainFrame();
				// Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
				// application.setSize(d);
				application.addWindowFocusListener(application);
				application.addMouseListener(new java.awt.event.MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						bg.pnl.addPosition(e);
						
					}

				});

				application.setVisible(true);
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	public static TransparentScreen bg;
	// End of variables declaration//GEN-END:variables
	int i;

	public void windowGainedFocus(WindowEvent e) {
		// System.out.println("windowGainedFocus step : "+i++);
		if (!bg.pnl.isRunning) {
			this.setSize(bg.pnl.width, bg.pnl.height);
			bg.refresh();
			Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
			this.setSize(d);
		}
	}

	public void windowLostFocus(WindowEvent e) {
		// System.out.println("windowLostFocus step : "+i++);
		// this.setVisible(!flag);
		// flag=!flag;

		// bg.refresh();
	}

}
